//1.引入样式表
//公用样式 
require('../../assets/css/index.less');
require('../../assets/fonts/iconfont.css');
// weui
require("../../lib/weui/weui.css")
let weui = require("../../lib/weui/weui.js")
// 当前页面样式
require('./mine.less')

//2.引入工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');
// 轮播图
//ES6方式
import Swiper, { Pagination, Autoplay } from 'swiper';
//引入swiper样式
import 'swiper/swiper-bundle.min.css';
Swiper.use([Pagination, Autoplay])
// 3.当前页面的js
dom.ready(function () {
    //加载底部菜单
    dom.bMenu('mine')
    new Swiper('.swiper', {
        //direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },
    })
    function getUserInfo() {
        https.get("/api/user/info", res => {
            let { errno, data } = res
            console.log(data,"用户数据");
            if (errno == 0) {
                dom.getEle("#imgBtn").src = ' http://fitness.h5.itsource.cn:3701' + data.imgUrl;
                dom.getEle("#nickname").textContent = data.nickName
                dom.getEle("#intro").textContent = data.sign
                dom.getEle("#days").innerHTML = data.clockCount;
                dom.getEle("#Duration").innerHTML = data.duration
                dom.getEle("#Calorie").innerHTML = data.calorie
                local.set("userData", data)
            }
        })
    }
    getUserInfo()
    function getSportData(){
        https.get("/api/exercise",res=>{
            console.log(res,"运动数据");
            if(res.errno == 0){
                local.set("sportData",res.data)
            }
        })
    }
    getSportData()
    function getClock() {
        https.get("/api/user/clockInInfo", function (res) {
            let { errno, data } = res;
            if (errno == 0) {
                dom.getEle("#bradge").innerHTML = data.isClockIn ? "已经打卡" : "今日打卡";
                dom.getEle("#days").innerHTML = clockCount;
            }
        })
    }
    getClock()


    dom.addEvent("#bradge", function () {
        https.post('/api/user/clockIn', {}, function (res) {
            let { errno, message } = res;
            if (errno == 0) {
                alert('打卡成功')
                getClock()
            } else {
                alert('打卡失败')
            }
        })
    })

    dom.addEvent("#exitBtn",function(){
        local.remove("tk")
        local.remove("user")
        local.remove("sportData")
        local.remove("userData")
        local.remove("videoS")
        location.href="login.html"
    })
})